package com.iwomy.envpro.platform;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.iwomy.envpro.platform.constant.RedisConstants;
import com.iwomy.envpro.platform.entity.AirMonitorEquipmentEntity;
import com.iwomy.envpro.platform.service.AirMonitorEquipmentService;
import com.iwomy.envpro.platform.utils.RedisClient;
import lombok.extern.slf4j.Slf4j;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.Set;

@Slf4j
public class EnvproPlatformInitialization {


	@Resource
	private AirMonitorEquipmentService airMonitorEquipmentService;
	@Resource
	private RedisClient redisClient;

	@PostConstruct
	private void init() {
		//项目刚启动的时候初始化所有设备为离线状态
//		List<Integer> list = new ArrayList(Arrays.asList(20, 30, 40));
		LambdaUpdateWrapper<AirMonitorEquipmentEntity> updateWrapper = Wrappers.lambdaUpdate(AirMonitorEquipmentEntity.class)
				.set(AirMonitorEquipmentEntity::getStatus, 1).eq(AirMonitorEquipmentEntity::getStatus, 20);
		airMonitorEquipmentService.update(updateWrapper);
		log.info("初始化项目,设备全部离线");

		Set<String> strings = redisClient.listKeyByPrefix(RedisConstants.ENVPRO_DEVICS_CONFIG_KEY);
		if (ObjectUtil.isEmpty(strings)) return;
		strings.stream().forEach(redisClient::del);


	}

}
